<?php
$this->breadcrumbs = array(
	'Mitglieder' => array('index')
);

$this->menu = array(
	array('label' => 'Ehemalige Mitglieder', 'url' => array('old')),
//	array('label'=>'Liste exportieren', 'url'=>array('export/excel')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	$('#grid-buttons').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('member-grid', {
		data: $(this).serialize()
	});
	return false;
});
");

Yii::app()->clientScript->registerScript('export-extended', "
$('#export-extended-button').on('click',function() {
    $.fn.yiiGridView.export();
});
$.fn.yiiGridView.export = function() {
    $.fn.yiiGridView.update('member-grid',{
        success: function() {
            $('#member-grid').removeClass('grid-view-loading');
            window.location = '" . $this->createUrl('export/excel?') . "' + $('.search-form form').serialize();
        },
        data: $('.search-form form').serialize() + '&export=true'
    });
}
");

Yii::app()->clientScript->registerScript('export', "
$('#export-button').on('click',function() {
    $.fn.yiiGridView.export();
});
$.fn.yiiGridView.export = function() {
    $.fn.yiiGridView.update('member-grid',{
        success: function() {
            $('#member-grid').removeClass('grid-view-loading');
			window.location = $('.keys').attr('title').replace('member/index', 'export/excel');
        },
        data: $('.search-form form').serialize() + '&export=true'
    });
}
");
?>

<h1>Mitgliederliste</h1>

<p>
	Du kannst optional ein Vergleichsoperator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
	or <b>=</b>) am  Anfang jedes Suchfeldes eingeben.
</p>

<?php echo CHtml::link('Erweiterte Suche', '#', array('class' => 'search-button')); ?>
<div class="search-form" style="display:none">
	<?php
	$this->renderPartial('_search', array(
		'model' => $model,
		'codes' => $codes,
	));
	?>
</div><!-- search-form -->

<div style="margin-top: 20px; clear: both;" id="grid-buttons">
	<?php echo CHtml::submitButton('Suchen', array('class' => 'span-3 button')); ?>
<?php echo CHtml::button('Exportieren', array('id' => 'export-button', 'class' => 'span-3 button')); ?>
</div>

<?php
$this->widget('zii.widgets.grid.CGridView', array(
	'id' => 'member-grid',
	'dataProvider' => $model->search(),
	'filter' => $model,
	'selectableRows' => 1,
	'ajaxUpdate' => 'false',
	'selectionChanged' => 'function(id){ location.href = "' . $this->createUrl('view') . '/id/"+$.fn.yiiGridView.getSelection(id);}',
	'columns' => array(
		array(
			'name' => 'Vorname',
			'htmlOptions' => array('width' => '100')
		),
		array(
			'name' => 'Name',
			'htmlOptions' => array('width' => '100'),
		),
		array(
			'name' => 'Strasse',
			'htmlOptions' => array('width' => '150')
		),
		array(
			'name' => 'Hausnummer',
			'value' => '$data->Hausnummer > 0 ? $data->Hausnummer : ""',
			'htmlOptions' => array('width' => '20')
		),
		array(
			'name' => 'PLZ',
			'htmlOptions' => array('width' => '20')
		),
		array(
			'name' => 'Ortschaft',
			'htmlOptions' => array('width' => '100')
		),
		array(
			'name' => 'member_type_search',
			'value' => 'stripos($data->membership->Klasse_Verband, "Symp") === 0 ? "Sympi" : "Mitglied"',
			'htmlOptions' => array('width' => '60'),
			'filter' => array('asse' => 'Mitglied', 'symp' => 'Sympi'),
		),
	),
));
?>
